// import api from "../../http/api";
import {
	log
} from 'util';
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		hasLogin: false, //是否登录
		userInfo: {}, //用户信息
		networkState: true, //网络状态
	},
	mutations: {
		//监听网络状态变化
		changeWorksState(state) {
			uni.getNetworkType({
				success: function(res) {
					if (res.networkType === "none") {
						//无连接
						state.networkState = false;
					} else {
						state.networkState = true;
					}
				}
			});
		},
		//存储登陆信息
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({
				key: 'userInfo',
				data: provider
			})
		},
	},
	actions: {
		//登录请求
		// async
		logins({
			commit
		}, username) {
			console.log(commit, username)
			commit('login', username)
			// let res = await api(username);
			// if (res.data.status === 200) {
			//储存信息
			// localStorage.setItem("adminToken", res.data.token);
			// localStorage.setItem("adminUser", JSON.stringify(res.data));
			//跳转路由
			// uni.navigateTo({
			// 	url: 'pages/pages/index'
			// });
			//提示用户
			// commit("setMenus", res.data);
			// Message.success("登录成功");
			// } else {
			// 	Message.error(res.data.msg);
			// }
		},
	}
})
export default store
